<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="手机号" prop="h5Tel">
        <el-input
          v-model="queryParams.h5Tel"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['pxy-staff:h5:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="h5List">
      <el-table-column label="序号" align="center" prop="ehid" />
      <el-table-column label="手机号" align="center" prop="h5Tel" />
      <el-table-column label="用户类型" align="center" prop="serviceType" :formatter="serviceType"/>
      <el-table-column label="最近登陆时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="openId" align="center" prop="openId" />
      <el-table-column label="aliOpenId" align="center" prop="aliOpenId" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handlereport(scope.row)"
          >查看消费记录</el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleDelete(scope.row)"
            v-hasPermi="['pxy-staff:h5:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listH5, getH5, delH5, addH5, updateH5 } from "@/api/pxy-staff/h5";
import {getPark} from "@/api/pxy-report/park";

export default {
  name: "H5",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // H5人员表格数据
      h5List: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        h5Tel: null,
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询H5人员列表 */
    getList() {
      this.loading = true;
      listH5(this.queryParams).then(response => {
        this.h5List = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        ehid: null,
        code: null,
        status: null,
        deleted: null,
        createTime: null,
        updateTime: null,
        h5Tel: null,
        serviceType: null,
        openId: null,
        aliOpenId: null
      };
      this.resetForm("form");
    },
    serviceType(row){
      return row.serviceType === 0 ? '微信' : '支付宝'
    },
    handlereport(row) {
      this.reset();
      const ehid = row.ehid || this.ids
      getH5(ehid).then(response => {
        this.form = response.data;
        this.$router.push({
          name: 'check',
          query: this.form
        })
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ehids = row.ehid || this.ids;
      this.$modal.confirm('是否确认删除H5人员编号为"' + ehids + '"的数据项？').then(function() {
        return delH5(ehids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('pxy-staff/h5/export', {
        ...this.queryParams
      }, `h5_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
